<?php
require_once FOREGROUND_COMMON_ACTION_SERVICE_DIR . '/ajax.php';

class foreground_member_address_delete_action_service extends foreground_ajax_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {	     		     
	    //var_dump(__METHOD__); exit();
        //var_dump($_SESSION); exit();
    
        $result = array('status' => 0, 'message' => '', 'data' => array());
    
        //var_dump($_POST); exit();
        $address_id = init_user_data_key($_POST, 'address_id', 'int');
    
        $action_data = wwy_action::$data;
	    $session_member_info = $action_data['session_member_info'];
        $member_id = $session_member_info['id'];
        
        //$address_id = 0;            
        if(empty($address_id)){
            $result['status']  = -400;
            $result['message'] = '删除失败';
        }else{
            $model_foreground_member_address = wwy_resource_container::get_model_foreground_member_address();
            //var_dump($model_foreground_member_address); exit();            
            $where      = array(
                'id'        => $address_id,
                'member_id' => $member_id,
            );
            $address_row = $model_foreground_member_address->fetch_row($where);
            //var_dump($address_row); exit();
            
            if(empty($address_row)){
                $result['status']  = -400;
                $result['message'] = '删除失败';
            }else{    
                $where = array( 'ids' => array($address_id));
                $delete_result = $model_foreground_member_address->delete($where);
        
                if(!$delete_result){
                    $result['status']  = -4;
                    $result['message'] = '删除失败';
                }else{
                    $result['status']  = 1;
                    $result['message'] = '删除成功';
                }
            }
        }
        
        self::set_view_status($result['status']);
        self::set_view_message($result['message']);
    }
}